//const url = 'http://localhost:8888';
const url = 'http://47.96.89.11:8888';
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const productionGzipExtensions = ['js', 'css'];

const path = require("path");

function resolve(dir) {
  return path.join(__dirname, dir);
}

module.exports = {
  publicPath: process.env.VUE_APP_BASE_PATH || '/',// 系统路径

  // 输出目录
  outputDir: "dist",
  lintOnSave: true,
  // 是否为生产环境构建生成 source map？
  productionSourceMap: false,
  configureWebpack: config => {
   /* config.externals = {
      'vue':'Vue',
      'vue-router': 'VueRouter',
      'axios': 'axios',
      'element-ui': 'ELEMENT',

    };*/
    config.plugins.push(new CompressionWebpackPlugin({
      algorithm: 'gzip',
      test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
      threshold: 10240,
      minRatio: 0.8
    }));
  },
  // alias 配置
  chainWebpack: config => {
    config.plugins.delete('prefetch');
    config.plugins.delete('preload');
    config
      .plugin('webpack-bundle-analyzer')
      .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin);

    const svgRule = config.module.rule('svg');

    svgRule.uses.clear();
    svgRule
      .test(/\.svg$/)
      .include.add(path.resolve(__dirname, './src/icons/svg'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({symbolId: 'icon-[name]'});
    const fileRule = config.module.rule('file');
    fileRule.uses.clear();
    fileRule
      .test(/\.svg$/)
      .exclude.add(path.resolve(__dirname, './src/icons/svg'))
      .end()
      .use('file-loader')
      .loader('file-loader');
  },


  runtimeCompiler: true,

  devServer: {
    proxy: {
      '/': {                  //匹配前端接口前缀
        target: url,
        ws: true,
        changeOrigin: true,
        secure: false,        //接受在HTTPS上运行且具有无效证书的后端服务器
        pathRewrite: {
          '^/': ''     //代理请求将前缀替换服务前缀
        }
      }
    },
    port: 9091
  },


};
